package com.ogilvy.cms.dao.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.ogilvy.cms.bean.CmsDictionary;
import com.ogilvy.cms.dao.CmsDictionaryDao;
import com.ogilvy.frame.hibernate.BaseDaoImpl;
import com.ogilvy.frame.util.SqlReplace;

@Repository
public class CmsDictionaryDaoImpl extends BaseDaoImpl<CmsDictionary> implements CmsDictionaryDao {
	public List<CmsDictionary> getListByScreen(Map<String,String> screenMap) {
		StringBuffer hql = new StringBuffer();
		hql.append("from com.ogilvy.cms.bean.CmsDictionary cd where ");
		hql.append(" cd.cmdName like '%"+screenMap.get("cmdName")+"%'");
		if(null != screenMap.get("parentId")&& !"".equals(screenMap.get("parentId")))
		{
			hql.append(" and  parentCmdId = '"+screenMap.get("parentId")+"'");
		}
//		if(!"".equals(screenMap.get("startTime")))
//		hql.append(" and  CONVERT(varchar(100), cd.cmdAddtime, 23)>=convert(date,'"+screenMap.get("startTime")+"')");
//		if(!"".equals(screenMap.get("endTime")))
//		hql.append(" and  CONVERT(varchar(100), cd.cmdAddtime, 23)<=convert(date,'"+screenMap.get("endTime")+"')");
		// 建立查询语句
		Query query = getSession().createQuery(SqlReplace.replace(hql.toString()));
		List<CmsDictionary>  list = query.list();
		if (list == null) {
			list = new ArrayList<CmsDictionary>();
		}
		return list;
	}
}
